package com.z.test;

import java.util.Arrays;

public class BubbleSort {
    private static int[] arr = new int[]{1,4,3,5,6,2};

    // 冒泡排序
    public static void bubble_sort(int[] arrs){
        int[] arr = Arrays.copyOf(arrs,arrs.length);
        int len = arr.length;
        System.out.println("冒泡排序 bubble sort:");
        printArrs("原始：" , arr);

        for(int i = 0; i < len - 1; i++){
            for(int j = 0; j < len - 1 - i; j++){
                if(arr[j] > arr[j + 1]){
                    int temp = arr[j + 1];
                    arr[j + 1] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        printArrs("最终：", arr);
    }
    public static void main(String[] args) {
        bubble_sort(arr);
    }







    static void printArrs(String preStr , int[] arr){
        String str = "";
        for(int i=0;i<arr.length;i++){
            str += arr[i] + ",";
        }
        System.out.println(preStr + str.substring(0,str.length()-1));
    }
}
